//
//  DLShowFormWholeContentVC.m
//  delongzhitou
//
//  Created by Mr.Wang on 2019/1/21.
//  Copyright © 2019 delongzhitou. All rights reserved.
//

#import "DLShowFormWholeContentVC.h"

@interface DLShowFormWholeContentVC ()

@end

@implementation DLShowFormWholeContentVC

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self setUpNav];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self layoutSubControls];
    // Do any additional setup after loading the view.
}
- (void) setUpNav {
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.translucent = NO;
}
- (void) layoutSubControls {
    
    self.view.backgroundColor = kColorRGBA(240, 240, 240, 1);
    
    self.titleView.title = self.showTitle;
    
    UIView *bgView = [UIView new];
    bgView.frame = CGRectMake(15, 15, kScreenWidth - 30, kScreenSafeAreaHeight - kHeightNavigation - 30);
    bgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bgView];
    
    
    
    UIView *leftView = [UIView new];
    leftView.frame = CGRectMake(15, 19, 5, 15);
    leftView.backgroundColor = kColorRGB(5, 99, 234);
    [bgView addSubview:leftView];
    
    UILabel *titleLabel = [UILabel new];
    titleLabel.frame = CGRectMake(leftView.right + 9, leftView.top, bgView.width - leftView.right - 18, leftView.height);
    titleLabel.textAlignment = NSTextAlignmentLeft;
    titleLabel.textColor = kColorRGB(85, 85, 85);
    titleLabel.font = kSystemFont(14);
    [bgView addSubview:titleLabel];
    titleLabel.text = self.showTitle;
    
    UITextView *contentTextView = [UITextView new];
    contentTextView.frame = CGRectMake(leftView.left, leftView.bottom + 5, bgView.width - 30, bgView.height - titleLabel.bottom - 15 - 20);
    contentTextView.backgroundColor = [UIColor whiteColor];
    contentTextView.editable = NO;
    contentTextView.font = kSystemFont(15);
    contentTextView.textColor = kDLNormalBlackColor;
    contentTextView.scrollEnabled = NO;
    [bgView addSubview:contentTextView];
    contentTextView.text = self.wholeContent;
    
    CGFloat newHeight = [contentTextView.text getValue4HeightWithWid:bgView.width - 30 andFont:kSystemFont(15)];
    
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:self.wholeContent];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:5];//调整行间距
    [attrStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, self.wholeContent.length)];
    
    [attrStr addAttribute:NSFontAttributeName value:kSystemFont(15) range:NSMakeRange(0, self.wholeContent.length)];
    
    newHeight = [contentTextView.text attrGetValue4HeightWithWid:bgView.width - 30 andFont:kSystemFont(15) andLineSpace:paragraphStyle];
    
    contentTextView.attributedText = attrStr;
    
    if (newHeight <= 30) {
        [contentTextView resetHeight:30];
        [bgView resetHeight:contentTextView.bottom + 20];
    } else if (newHeight <= kScreenSafeAreaHeight - kHeightNavigation - bgView.top - leftView.bottom - 5 - 20){
        [contentTextView resetHeight:newHeight + 20];
        [bgView resetHeight:contentTextView.bottom + 20];
    } else {
        contentTextView.scrollEnabled = YES;
        [contentTextView resetHeight:kScreenSafeAreaHeight - kHeightNavigation - bgView.top - leftView.bottom - 5 - 20];
        [bgView resetHeight:kScreenSafeAreaHeight - kHeightNavigation - 30];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
